<?PHP

$password = $_POST['password'];
$email = $_POST['email'];
if (!empty($_GET['flag'])) {
    $flag = $_GET['flag'];
} else {
    $flag = '';
}

$mysqli = mysqli_init();
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2); //设置超时时间
$mysqli->real_connect('127.0.0.1', 'root', 'mysql');
$sql = "CREATE DATABASE IF NOT EXISTS CUPT DEFAULT CHARSET utf8 COLLATE utf8_general_ci;";
if ($mysqli->query($sql) == TRUE) {
    //printf("Table CUPT successfully created.\n");
}
mysqli_select_db($mysqli, "CUPT");
//建表
if ($flag == 0) {
    $sql = "select * from participant where `email`='$email' and `password`='$password';";
} elseif ($flag == 1) {
    $sql = "select * from judge where `email`='$email' and `password`='$password';";
}
$rst = $mysqli->query($sql);
if ($rst->num_rows < 1) {
    echo '<br />用户名或密码错误！<br />';
    echo '<a href="javascript :;" onClick="javascript :history.back(-1);">回到登录界面</a>';
} else {
    echo '<br />登录成功';
    if ($flag == 0) {
        header("Location: particpant-index.html?email=$email");
        exit;
    } elseif ($flag == 1) {
        header("Location: judge-index.html?email=$email");
        exit;
    }
}
mysqli_close($mysqli);
?>
